﻿package src.index_copa{
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import src.*;
	public class Login extends MovieClip {
		private var swfId:String;
		public function Login() {
			swfId = ExternalInterface.objectID;
			form_init();
		}
		//form
		private function form_init():void {
			var bt:MovieClip = submit as MovieClip;
			bt.buttonMode = true;
			bt.addEventListener(MouseEvent.MOUSE_OVER, overHd);
			bt.addEventListener(MouseEvent.MOUSE_OUT, outHd);
			bt.addEventListener(MouseEvent.CLICK, submitHd);
			var str:String = "";
			str += 'var divObj=document.createElement("div");document.body.appendChild(divObj);';
			str += "divObj.innerHTML='";
			str += '<form id="login_form" method="post" action="user.do"><input type="hidden" name="username" /><input type="hidden" name="password" /></form>';
			str += "';";
			ec(str);
			//
			var bt_adv:MovieClip = signup.reg_adv as MovieClip;
			bt_adv.tabEnabled = false;
			bt_adv.buttonMode = true;
			bt_adv.addEventListener(MouseEvent.MOUSE_OVER, overHd);
			bt_adv.addEventListener(MouseEvent.MOUSE_OUT, outHd);
			bt_adv.addEventListener(MouseEvent.CLICK, advHd);
			var bt_pub:MovieClip = signup.reg_pub as MovieClip;
			bt_pub.tabEnabled = false;
			bt_pub.buttonMode = true;
			bt_pub.addEventListener(MouseEvent.MOUSE_OVER, overHd);
			bt_pub.addEventListener(MouseEvent.MOUSE_OUT, outHd);
			bt_pub.addEventListener(MouseEvent.CLICK, pubHd);
		}
		private function overHd(e:Event):void {
			e.currentTarget.alpha = 0.6;
		}
		private function outHd(e:Event):void {
			e.currentTarget.alpha = 1;
		}
		private function submitHd(e:Event):void {
			var user:String = username.text;
			var pass:String = password.text;
			//O.o(user + "|" + pass);
			var str:String = "";
			if (user == "") {
				str = "alert('Please enter the Username!');";
			} else if (pass == "") {
				str = "alert('Please enter the Password!');";
			} else {
				str += 'var myform = document.getElementById("login_form");';
				str += 'myform.username.value = "'+user+'";';
				str += 'myform.password.value = "'+pass+'";';
				str += 'myform.submit();';
			}
			ec(str);
		}
		private function advHd(e:Event):void {
			var str:String = "window.location='adv_reg_step1.do';";
			ec(str);
		}
		private function pubHd(e:Event):void {
			var str:String = "window.location='pub_reg_step1.do';";
			ec(str);
		}
		private function ec(s:String):void {
			if (ExternalInterface.available) {
				try {
					ExternalInterface.call("eval", s);
				} catch (error:Error) {
					O.o("An Error occurred: " + error.message);
				}
			} else {
				O.o("Error: External interface is not available for this container.");
			}
		}
	}
}